package com.idol.util;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Supreme_Sir
 * @version 1.0
 * @className ConnectionUtil
 * @description 获取当前线程数据源连接
 * @date 2020/10/13 10:19
 **/
public class ConnectionUtil {
    private ThreadLocal<Connection> currentConnectionThread = new ThreadLocal<>();

    public Connection getCurrentThreadConn() throws SQLException {
        Connection connection = currentConnectionThread.get();
        if (connection == null) {
            connection = DataSourceUtil.getConnection();
            currentConnectionThread.set(connection);
        }
        return currentConnectionThread.get();
    }
}
